package com.fitness.front.config;

import cn.dev33.satoken.interceptor.SaInterceptor;
import com.fitness.front.service.impl.common.UploadFileServiceImpl;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class SaTokenWebMvcConfig implements WebMvcConfigurer {

    /**
     * 默认拦截器 其中lang表示切换语言的参数名
     *
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册 Sa-Token 拦截器，打开注解式鉴权功能
        registry.addInterceptor(new SaInterceptor()).addPathPatterns("/api/v1/**");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/file/**")
                .addResourceLocations("file:" + UploadFileServiceImpl.DEFAULT_UPLOAD_FOLDER );
    }
}
